This page last changed on Jul 08, 2006 by charles.

Shapefile

For users who don't have a spatial database already set up and want to get GeoServer running quickly, we offer support for Shapefiles directly in GeoServer. You can even perform transactions against Shapefiles, modifying them through the WFS-T interface. But we do not really recommend it, as they weren't designed for such purposes. Any production instance of GeoServer should use a spatial database, PostGIS has a great shp2pgsql tool to easily turn your shapefiles into PostGIS tables.

Thanks goes to the GeoTools team for this great contribution, and especially Ian Schneider, for getting things good to go for GeoServer.

The main field of the Shapefile DataStore is the url. A url is just a location, it need not be an online location (though it can be). In the case of shapefiles the most likely case is that you have the files somewhere on your computer. For GeoServer you have the choice of copying them into your GeoServer data directory, and referring to them relative to the base directory, or leaving them where they are and entering the url in your file system. The included sample shapefiles make use of the first way, but that's because we have no idea where you might put GeoServer, so can not refer to them on your file system, since we don't know the absolute location.

All file url's that start with file:data/ are interpreted byGeoServer as relative ones. This means that GeoServer will figure out the root directory for you automatically. This is best for those wanting to transfer a GeoServer configuration to another computer, as you can just include all the Shapefiles that are needed and refer to them relatively. An example of this is the states shapefile, its url is:

file:data/featureTypes/states/states.shp

Note that the web admin tool does some magic as to where to place the files. If you are adding a new shapefile we recommend that you put it in the featureTypes directory named datastoreid_shapefileName where datastoreid is the value you assign it when you create the new datastore, and shapefileName is the name of the actual file. Doing this has the nice effect of creating the configuration files in the same directory as the actual shapefiles, and thus making all directly available for download from the same spot (if you don't do this everything will still work, the files will just be in different locations, unless you move the generated config files back to your shapefile directory). Which brings up the other nice effect of using the relative locations, users can directly download the shapefiles, by just accessing it through the web. Try going to:
*http://localhost:8080/geoserver/data/featureTypes/bc_roads/

All the shapefiles are there, as well as the configuration files (note that the catalog.xml file, that contains sensitive passwords, is notaccessible through the web, which is by design). In the future we are considering making GeoServer more of a full data distribution server, where it would make all layers (even database ones) available for direct download with generated shapefiles (link to jira). But for now any shapefile you put up will be available for download.

If you specifically don't want your shapefile available for download, then we recommend just inputting its absolute path. This is done differently on linux and windows file systems. On windows you wouldspecify the url as something like:

Windows
file:/C:/Documents and Settings/Chris/My Documents/shapefiles/states.shp

Notice the drive letter is specified, followed by a typical filepath.

In Linux you would not specify the drive letter, just the location on the file system:

Linux
file:/home/cholmes/shapefiles/states.shp

Note that a consequence of using the Url is that you actually can refer to a shapefile that is online. We certainly don't recommend it, you should instead download the file to the same computer GeoServer is running on, so you're not sending network requests every time. But it is an interesting example of how you can spread your resources around and have GeoServer centralize them and share them with the world.

There are two other optional parameters for Shapefiles. The memory mapped buffer should generally be set to true, it's more for programmers. The dbf charset parameter specifies a Character Set to be used to read the DBF file (the file that contains the attributes of the Shapefile). The default is ISO-8859-1.

Indexed Shapefile

The Shapefile (Indexed) option works just like the normal shapefile, except you can click the option to 'create spatial index', which will create a new index if there's not one already. You can leave the rest of the options at their defaults (todo: explain what the other options are, I think that memory mapped doesn't really matter at all, some programmer option, and I have no idea about the index type, but leaving it blank will suffice. Also these datastores should just be combined...)

So can someone give a simple example? What would the Shapefile look like for, say, a simple box to be drawn around a city block, given the latitude and longitude of each of the corners of the intersections that surround it?

Posted by scienceman at Jun 12, 2006 16:33

Geoserver 1.3 will not allow spaces in file paths in the Windows file path URL.

Posted by khudak at Sep 11, 2006 07:38
Document generated by Confluence on Jan 16, 2008 23:27